Skip to content

feat(auth): browser sign-in, standalone organizations and qualified channels - #145

Merged
xergioalex merged 19 commits into
mainfrom
feature__standalone_auth_program
Nov 13, 2026
Merged

xergioalex merged 19 commits into
mainfrom
feature__standalone_auth_program

Conversation

@xergioalex

Copy link
Copy Markdown
Member

Summary

Adds browser sign-in (dailybot login --device) with self-renewing sessions, plus support for standalone Dailybot organizations, their chat platforms and qualified channel references. Device login is opt-in; the email code is unchanged.

⚠️ Do not merge or release until API PR 4 is in production. Device login needs the API's PLAN_011 device doors (/v1/cli/auth/device/, /device/token/, /refresh/). Merging cuts a release automatically. Expected version: 3.29.0, which is the API's CLI_MIN_VERSION.

Changes

Sign-in and sessions

  • dailybot login --device: RFC 8628 browser sign-in. It is opt-in for now (DEVICE_LOGIN_IS_DEFAULT = False). A 404/405 on the start door falls back to the email code.
  • credentials.json gains auth_method, refresh, expires_at and refresh_expires_at. Keys are only added; a legacy file is unchanged.
  • The client refreshes a browser session only on 401 access_token_expired: one refresh, one replay. The rotated pair is written atomically, and another CLI process's rotation is adopted.
  • logout revokes both tokens, with the refresh-body form once the access token has expired.
  • A 503 auth_backend_unavailable gets a bounded retry and never means a logout, a refresh or an API-key fallback.
  • Every API request sends the X-Dailybot-Client / X-Dailybot-Client-Version telemetry headers.

Standalone organizations and channels

  • The login picker marks standalone orgs "(Dailybot)".
  • dailybot org lists the org's chat platforms.
  • The cached plan tier is re-read from /v1/organization/, so trials are no longer blocked locally.
  • --channel accepts slack:<id>, msteams:<id>, discord:<id>, hangouts:<id> and <platform-id>:<id>. dailybot: is refused.
  • platform_not_connected is pinned for chat send: the message is never redirected to Dailybot Chat.
  • A one-time cli_auth_deprecated notice appears on email-code sign-in, plus catalogue messages for the session, sign-in and chat-platform codes.

Docs: README, API_REFERENCE, CONFIGURATION, SECURITY, TROUBLESHOOTING, TESTING_GUIDE, PERFORMANCE, CLI_COMMAND_BEST_PRACTICES, ARCHITECTURE and the AGENTS.md index.

Test plan

Automated

  • Run pytest -q: 4,223 pass, all against recorded wire fixtures with HTTP mocked.
  • Run ruff check dailybot_cli tests and mypy dailybot_cli: both clean.

Manually, once API PR 4 is live on a test server

  • dailybot --api-url <server> login --device, approve in the browser, then run dailybot status.
  • Wait over an hour (or expire the access token server-side), then run a command; it refreshes without a prompt.
  • Run dailybot logout; the session is revoked on the server.

Regression

  • dailybot login --email [email protected] --code 123456 writes exactly the five legacy credentials.json keys.
  • Against a server without the device doors, login --device falls back to the email code.

Risks

Auth transport and the stored credential schema change. The effect is limited to browser-signed-in sessions, since legacy sessions never refresh. Rollback: revert the PR. Keys are only added to credentials.json, so older CLIs keep reading it, and a device session falls back to dailybot login once its access token expires.

One deliberate behaviour change: on a cached free plan, the CLI now makes one /v1/organization/ read (at most every 10 minutes per org) before blocking a command, instead of zero.

🤖 Generated with Claude Code

xergioalex and others added 17 commits November 13, 2026 13:46
## Summary
One recorded response per new door and state (device start, every
device-token state, the token pair body, refresh failures, the session
401 codes, the defensive 503, the deprecation field, org selection,
/v1/organization/ with and without chat platforms and plan, and the
channel-reference codes), plus a drift test against the frozen record.

## Change Log
- tests/fixtures/device_flow/*.json: {door, status, headers, body}, fake ids only
- tests/wire_fixture_loader.py: load_fixture / fixture_body / fixture_response
- tests/wire_fixtures_test.py: shape, frozen values and no-real-identifier checks
- docs/TESTING_GUIDE.md: fixtures location

## Risks
- None: test data only

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…als.json

## Summary
A browser (device-flow) session stores its access token in `token`, so
every call path and older CLIs keep working, and adds `auth_method`,
`refresh`, `expires_at` and `refresh_expires_at`. Legacy email-code
sessions keep exactly the five legacy keys.

## Change Log
- save_credentials(..., refresh=, expires_at=, refresh_expires_at=)
- update_token_pair: rotate the pair in place, keep every other key, 0o600
- is_pair_session, get_refresh_token, get_refresh_token_for (host-bound)
- docs/CONFIGURATION.md: the new keys and the no-migration note

## Risks
- None for legacy files: keys are only added (Rule 16)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
start_device_authorization, poll_device_token and refresh_token_pair send
the frozen checkpoint-1 requests without any credential. Device-token
states surface as APIError.code (slow_down's interval in extra) and are
never retried as authentication failures.

## Change Log
- DEVICE_CLIENT_ID / DEVICE_GRANT_TYPE constants
- poll timeout message says polling again is safe
- tests built on the recorded fixtures; docs/API_REFERENCE.md rows

## Risks
- None: new methods only, nothing calls them yet

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
Every request to the Dailybot API now carries `X-Dailybot-Client: cli`
and `X-Dailybot-Client-Version: <installed version>` beside the
User-Agent, so the server can classify CLI traffic. Presigned storage
uploads and downloads carry neither.

## Change Log
- CLIENT_HEADER / CLIENT_VERSION_HEADER / CLIENT_HEADER_VALUE in _base_headers
- tests on unauthenticated, user, agent and storage paths

## Risks
- None: telemetry only, never used for authorization

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
The RFC 8628 device flow: the CLI prints a Dailybot link and a short code,
polls at the server's interval (adopting slow_down's interval, capped at
30 s), stops cleanly on denial, expiry and invalid requests, and saves the
access/refresh pair, the org and its effective tier. A 404/405 on the
start door falls back to the email code. The flow is opt-in for now
(DEVICE_LOGIN_IS_DEFAULT = False) until the API doors are live; the
email-code paths are unchanged.

## Change Log
- commands/_device_login.py: start, poll loop, terminal states, save
- display.print_device_login_instructions (server text neutralized)
- login: --device flag; email is prompted only on the email path
- README and CLI_COMMAND_BEST_PRACTICES login sections

## Risks
- Nothing is written until the pair arrives; Ctrl-C leaves the stored
  session untouched

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
A device-flow session refreshes its pair only when a Bearer request is
refused with `401 access_token_expired`: one refresh, one replay. The
rotated pair is written atomically (0o600 temp file + os.replace). A pair
already rotated by another CLI process is adopted; on `session_revoked`
the file is re-read once (L36). Other 401 codes, 403s, legacy tokens and
DAILYBOT_CLI_TOKEN never refresh. A transport failure or a non-401 on the
refresh door is raised, never turned into an API-key fallback.

## Change Log
- DailyBotClient._needs_refresh / _refresh_session in _request and _agent_request
- config.update_token_pair: atomic replace
- docs: CONFIGURATION.md refresh lifecycle, SECURITY.md refresh-token handling

## Risks
- Rule 14 order and the host binding are unchanged; tests pin both

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
`dailybot logout` on a device-flow session sends the Bearer access while
it is valid, and the unauthenticated `{"refresh": ...}` body once the
access has expired (locally or as the server answers), so logout never
needs a refresh first. A legacy token's request is unchanged. When a
pair could not be revoked, the CLI says so after removing the local file.

## Change Log
- DailyBotClient.logout(refresh=, access_expired=) + _logout_with_refresh
- config.is_access_token_expired
- docs/CONFIGURATION.md logout note

## Risks
- None for legacy sessions: same request, same output

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
A `503` with `code: auth_backend_unavailable` is retried 3 times, each
waiting `min(Retry-After, 5 s)` (2 s when absent), at the send level, so
it never reaches the 401 refresh or the API-key fallback and never
touches credentials.json. After the budget, commands print "Dailybot
sign-in is temporarily unavailable" and exit 6 (wait and retry); logout
keeps the local session so it can be retried. Defensive: CLI tokens are
DB-validated and should never meet this 503.

## Change Log
- AUTH_BACKEND_* constants, _retry_auth_backend in _guard_transport and _dispatch_guarded
- ERROR_CODE_MESSAGES entry and exit mapping; logout guard
- docs/TROUBLESHOOTING.md: the 503 and the device-login outcomes

## Risks
- Other 503s are unchanged (no retry, same rendering)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
Org selection lists that include standalone organizations (frozen marker
`standalone: true`) now label them "<name> (Dailybot)" in the interactive
and numbered pickers, so a Slack workspace and the standalone org with
the same name are told apart. `--org <uuid>` resolves them as any other
org; the machine-pipeable `_print_org_list` lines are unchanged, and
agents.json is never touched by a login.

## Change Log
- org_choice_label + STANDALONE_ORG_HINT in commands/auth.py
- tests with the recorded selection fixture (picker, numbered, --org)

## Risks
- None: the label is display-only; agent orgs (platform dailybot without
  the marker) keep their plain name

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
The cached tier no longer blocks commands the server would allow. On a
cached-free hit, and on a `plan_upgrade_required` answer, the CLI
re-reads `plan.effective_tier` from `/v1/organization/` (at most once per
org every 10 minutes) and updates plan_cache.json; `dailybot org` writes
it too. A payload for another org is never cached, an absent `plan` (L43,
switched off) keeps the cached tier, and a failed read never blocks.

## Change Log
- public_api_helpers: refresh_cached_tier, remember_effective_tier,
  TIER_REFRESH_MIN_INTERVAL_SECS; enforce_plan_access and exit_for_api_error use them
- config: additive `_refreshed_at` throttle key in plan_cache.json
- plan_access_test: updated to the L37 contract (one tier read, never the
  command's own request)
- docs: CONFIGURATION.md plan_cache.json, PERFORMANCE.md budget note

## Risks
- Paid or unknown tiers make zero extra requests

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
When /v1/organization/ serves `has_external_chat_platform`,
`primary_chat_platform` and `chat_platforms` (ChatPlatformSummary, L74),
`dailybot org` lists each platform with its name, status, primary marker
and full id (the value installation-qualified references use), and says
when no external platform is connected. Missing keys mean "unavailable",
so the output is byte-identical to today; `--json` passes them through.

## Change Log
- display.print_org_chat_platforms (server text neutralized and escaped)
- docs/API_REFERENCE.md org fields; README org row

## Risks
- None: additive rendering only

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
`chat send` against an organization with no external chat platform keeps
the server's `400 platform_not_connected`: the catalogue message, exit 2,
the code in --json, and exactly the user's targets in one request (never
a retargeted Dailybot Chat delivery). No code change was needed; the
tests pin it so later channel work cannot regress it.

## Change Log
- chat_commands_test: TestPlatformNotConnected with the recorded fixture
- docs: TROUBLESHOOTING Chat section, API_REFERENCE send-message note

## Risks
- None

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
While the server's notice is on, the legacy request-code and verify-code
answers carry a `deprecation` field on 200 and 400 bodies. The CLI shows
one notice per login with the sunset date: `dailybot upgrade` when its
version is below `min_version`, otherwise a pointer to
`dailybot login --device`. The login completes as before; without the
field the output is unchanged. The server's `detail` prose is never
rendered.

## Change Log
- _handle_response: body `deprecation` → APIError.extra["deprecation"]
- auth: is_version_below, _notice_deprecation (once per run)
- display.print_cli_auth_deprecation; catalogue entry for the future 410
- docs: TROUBLESHOOTING, API_REFERENCE

## Risks
- None: a notice only, never blocks

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
ERROR_CODE_MESSAGES gains messages for the device-flow session codes
(access_token_expired, refresh_token_expired, session_revoked,
session_migrated, user_disabled), the RFC 8628 sign-in codes, the
chat-platform attach codes and the qualified channel-reference codes
(channel_reference_ambiguous / _unknown). The five session 401 codes
replace the generic "Session expired" line; every other 401 keeps it,
and unknown codes still show the server detail.

## Change Log
- catalogue entries + SESSION_401_CODES in public_api_helpers
- feature_not_available keeps its existing message (attach is web-only)
- docs/API_REFERENCE.md: error translation rows and code table

## Risks
- None for existing codes: their messages and exit codes are unchanged

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
`chat send --channel` and the Tasks route/report/notification channel
flags accept the frozen grammar: raw ids and names as today,
`slack|msteams|discord|hangouts:<id>` (split on the first colon, so a
Teams `19:` id stays raw) and `<platform-id>:<id>`. Qualified forms are
sent verbatim, only to organizations whose /v1/organization/ serves
`chat_platforms` (read once, only when a qualified reference is typed);
others get a usage error asking for the raw id. `dailybot:` is refused:
a message never goes to Dailybot Chat. The server's
channel_reference_ambiguous / _unknown render by code.

## Change Log
- _channels.py: parse_channel_reference, check_chat_channel_references,
  qualified branch in resolve_channel
- chat._execute_send checks the targets (send, update, --payload-json)
- docs: API_REFERENCE channel-reference table, README rows

## Risks
- Raw references are unchanged and cost no extra request

Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Summary
Reconcile the contributor and product docs with the branch: AGENTS.md
structure and test map, ARCHITECTURE (login and refresh paths, stored
keys), ECOSYSTEM_CONTEXT (the device-flow doors), PRODUCT_SPEC (sign-in
methods) and the README logout row.

## Risks
- None: docs only. CHANGELOG.md and the version stay with semantic-release

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xergioalex xergioalex added the Ready Trigger AI code review label Nov 13, 2026
@github-actions

This comment has been minimized.

github-actions[bot]

This comment was marked as outdated.

@github-actions github-actions Bot added the pr-reviewed Passed AI code review label Nov 13, 2026
## Summary
Five findings from the PR 145 review, each with a test.

## Change Log
- _refresh_session rejects an empty access or refresh, like login's
  _save_pair, and returns False when update_token_pair cannot persist
  the pair (no replay with an in-memory-only session)
- expires_at / refresh_expires_at are stored only as non-empty strings,
  else None (config.text_or_none in save_credentials, update_token_pair,
  _device_login and _refresh_session)
- resolve_channel refuses `dailybot:` with the same message as chat send
- interactive.py signs in through the same branch as `dailybot login`
  (browser flow when DEVICE_LOGIN_IS_DEFAULT is on, email code otherwise);
  the default stays False

## Risks
- None: stricter validation and one shared login entry point

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xergioalex xergioalex added Ready Trigger AI code review and removed Ready Trigger AI code review labels Nov 13, 2026
@github-actions

This comment has been minimized.

github-actions[bot]

This comment was marked as outdated.

…ck credential

## Summary
AI review round 1 also flagged (unthreaded, api_client.py:680 and :764)
that when a repo key preferred on the login's own host is refused and
the client falls back to the Bearer session, an expired access token was
never refreshed. Both request paths now refresh once after the fallback
too, and replay with the Bearer alone (the refused key is not resent).
Never more than one refresh per request.

## Change Log
- _request / _agent_request: refresh_tried guard, post-fallback refresh
- _bearer_headers, _replay_headers helpers
- tests: user path, agent path, single-refresh guard

## Risks
- Rule 14 order unchanged: the repo key still goes first; the Bearer
  stays host-bound

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xergioalex xergioalex added Ready Trigger AI code review and removed Ready Trigger AI code review labels Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

AI review for 2524a69 — ✅ done

View review →

Highest severity: warning

Verifier: 0 checked · 0 verified · 0 downgraded · 0 refuted · 0 unverified · 0 skipped — grok-4.5 (economy), 0s

Strictness gate: ✅ highest severity warning ≤ critical threshold

0 inline comment(s) attached.

Usage: 239.0k in (78% cached) · 3.5k out · est. $0.18 · 5 turns · 42s

Iteration-Aware Review: gen 3, round 1, policy=first-pass-exhaustive (new_commits, mode=incremental) — 0 surfaced.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review — 0 finding(s): 0 critical · 0 warning · 0 info

Check: ✅ passing — strictness block-on-critical: highest severity warning ≤ critical threshold

No findings posted inline.

Summary

Verdict

Solid follow-up — the expired-Bearer-as-fallback refresh gap is closed on both the user and agent paths, and the last open round-1 finding is resolved.

What changed since last review

DailyBotClient._agent_request and _request now allow at most one refresh per request, including the case where a preferred repo API key is refused first and the login Bearer that follows is already expired. The post-fallback replay uses _bearer_headers() / _replay_headers(..., self._bearer_headers(), ...) so the refused key is not sent again. Coverage is in TestRefreshAfterTheAlternateCredential (user path, agent path, and a one-refresh cap).

Prior finding

  • ef8269f2a26abb7d (docs/CLI_COMMAND_BEST_PRACTICES.md:1401) — resolved in f2c0f20. _login_interactively now branches on DEVICE_LOGIN_IS_DEFAULT the same way bare dailybot login does (device flow when the flag is on, email code otherwise). The docs sentence matches the code.

Residual notes (no new inline findings)

  • Do not merge or release until API PR 4 is in production (CLI_MIN_VERSION / expected 3.29.0), as the PR description already states — device doors must be live.
  • The deliberate free-plan re-read of /v1/organization/ remains an intentional behaviour change; no issue there.

Recommendation: approve


Since last review (f2c0f20 → 2524a69): resolved 0 · still open 1 · regressed 0 · new 0 · 1 claimed resolved but unverified.

Prior findings

  • still open docs/CLI_COMMAND_BEST_PRACTICES.md:140 — claimed resolved, unverified

Check status: ✅ passing — strictness block-on-critical, highest severity in effect warning: highest severity warning ≤ critical threshold.

This line is written by the reviewer runtime after the gate ran and matches the check conclusion and the tracking comment. Any recommendation above is the model's advisory opinion, not the gate.

Footnotes

  1. docs/CLI_COMMAND_BEST_PRACTICES.md:140 is mentioned above but is not a row of the findings table (not posted inline). ↩

@xergioalex
xergioalex merged commit fb72ca1 into main Nov 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-reviewed Passed AI code review Ready Trigger AI code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant